<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Object.defineProperty</title>
</head>
<body>
    <div id="app">
        <p>你好，<span id="name"></span></p>
    </div>
    <script>
        var obj = {};
        
        // 数据拦截
        Object.defineProperty(obj, 'name', {
            get(){
                console.log('有人想要获取name属性');
                return document.getElementById('name').innerHTML
            },
            set(nick){
                console.log('有人想要修改name属性');
                document.getElementById('name').innerHTML = nick;
            },
        })

        obj.name = 'jerry'
        console.log(obj.name);
        
    </script>
</body>
</html>